package org.alg.graph;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;

public class DepthFirstSearch {

	private boolean[] marked;
	private int count;
	
	public DepthFirstSearch(Graph G,int s){
		marked=new boolean[G.V()];
		dfs(G,s);
		
		for(int i=0;i<marked.length;i++){
			if(marked[i])
				System.out.println(i);
		}
	}
	
	private void dfs(Graph G,int v){
		System.out.println("access "+v);
		marked[v]=true;
		count++;
		for(int w:G.adj(v))
			if(!marked[w])dfs(G,w);
	}
	
	public boolean marked(int w){
		return marked[w];
	}
	
	public int count(){
		return count;
	}
	
	public static void main(String[] args) throws IOException{
		File f=new File("D:\\arg-data\\tinyG.txt");
		FileInputStream fis=new FileInputStream(f);
		Graph graph=new Graph(fis);
		DepthFirstSearch dfs=new DepthFirstSearch(graph, 1);
	}
}
